package com.dy.nygl.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.dy.nygl.mapper.CostAnalysisMapper;
import com.dy.nygl.pojo.CostAnalysis;
import com.dy.nygl.service.CostAnalysisService;

@Service("costAnalysisService")
public class CostAnalysisServiceImpl implements CostAnalysisService{
	
	@Resource(name="costAnalysisDao")
	private CostAnalysisMapper costAnalysisDao;
	
	public List<String> selectEnergyType(){
		return costAnalysisDao.selectEnergyType();
	}
	public List<Double> selectPrice(){
		return costAnalysisDao.selectPrice();
	}
	
	public List<CostAnalysis> selectAll(){
		return costAnalysisDao.selectAll();
	}
	
	public CostAnalysis selectOne(Integer id){
		return costAnalysisDao.selectByPrimaryKey(id);
	}
	
	// 添加能源，code获取
	public Integer selectCode(){
		List<Integer> sum = new ArrayList<>();
		for (String string2 : costAnalysisDao.selectCodeMapper()) {
			sum.add(Integer.parseInt(string2));
		}
		return sum.get(sum.size()-1);
	}

	public int addCost(CostAnalysis record){
		return costAnalysisDao.insert(record);
	}
	
	public int updateCost(CostAnalysis record){
		return costAnalysisDao.updateByPrimaryKey(record);
	}

	public int deleteCost(int id){
		return costAnalysisDao.deleteByPrimaryKey(id);
	}
	
	public String checkEneryType(String type){
		List<String> energytype = costAnalysisDao.selectEnergyType();
		for(int i = 0;i<energytype.size();i++){
			if(energytype.get(0).equals(type)){
				System.err.println("能源类型已存在");
				return "能源类型已存在！";
			}
		}
		return "能源类型不存在,可以使用！";
	}

}
